package com.stormrage.edu.dao.exam.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.exam.ExmExamDao;
import com.stormrage.entity.exam.ExmExam;
import com.stormrage.entity.exam.rep.ExmExamRep;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: ExmExamDaoImpl.java
 * @Package com.stormrage.edu.dao.exam.impl
 * @Description: 考试试题 Dao
 * @author www.stormragetech.com
 * @date 2016年5月16日
 * @version V1.0
 */
@Repository
public class ExmExamDaoImpl extends MysBaseDao implements ExmExamDao {

	private static final Logger logger = LoggerFactory.getLogger(ExmExamDaoImpl.class);

	@Override
	public ExmExam queryById(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 ExmExamDao 】-【 queryById 】-【 STARTED 】");

		final String query = "SELECT * FROM exm_exam WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		ExmExam entity = queryObject(query, ExmExam.class, map);

		logger.debug(" 【 Dao 】-【 ExmExamDao 】-【 queryById 】-【 COMPLETED 】");
		return entity;

	}

	@Override
	public List<ExmExamRep> queryListByRelate(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 ExmExamDao 】-【 queryListByRelate 】-【 STARTED 】");

		final String query = "SELECT id, type, question FROM exm_exam WHERE relate_type = :type AND relate_id = :relateId";
		logger.debug(" 数据库执行语句为 " + query);

		List<ExmExamRep> array = queryList(query, ExmExamRep.class, map);

		logger.debug(" 【 Dao 】-【 ExmExamDao 】-【 queryListByRelate 】-【 COMPLETED 】");
		return array;

	}

	@Override
	public List<ExmExamRep> queryListByTypeRelate(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 ExmExamDao 】-【 queryListByRelate 】-【 STARTED 】");

		logger.debug(" map为 " + map.toString());

		final String query = "SELECT * FROM exm_exam WHERE type = :type AND relate_type = :relateType"
				+ " AND relate_id = :relateId";
		logger.debug(" 数据库执行语句为 " + query);

		List<ExmExamRep> array = queryList(query, ExmExamRep.class, map);

		logger.debug(" 【 Dao 】-【 ExmExamDao 】-【 queryListByRelate 】-【 COMPLETED 】");
		return array;

	}

}
